﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Gmis.Public;

namespace Gmis.Web.Manage.Affairs
{
    public partial class ArtelMember : System.Web.UI.Page
    {
        #region 分页变量，与UI绑定
        private int numPerPage;
        /// <summary>
        /// 每页显示的条数
        /// </summary>
        public int NumPerPage
        {
            get
            {
                int temp = Convert.ToInt32(Request.Form["numPerPage"]);
                return temp == 0 ? 20 : temp;
            }
            set { numPerPage = value; }
        }

        private int pageNumShown = 10;
        /// <summary>
        /// 页数导航的个数
        /// </summary>
        public int PageNumShown
        {
            get { return pageNumShown; }
            set { pageNumShown = value; }
        }

        private int pageNum;
        /// <summary>
        /// 当前显示的页数
        /// </summary>
        public int PageNum
        {
            get
            {
                int temp = Convert.ToInt32(Request.Form["pageNum"]);
                return temp == 0 ? 1 : temp;
            }
            set { pageNum = value; }
        }

        private int totalCount;
        /// <summary>
        /// 总条数
        /// </summary>
        public int TotalCount
        {
            get { return totalCount; }
            set { totalCount = value; }
        }

        private string keywords;
        /// <summary>
        /// where语句，不加where与空格
        /// </summary>
        public string Keywords
        {
            get
            {
                string temp = Request.Form["keywords"];
                return temp;
            }
            set { keywords = value; }
        }

        private string orderField;
        /// <summary>
        /// 排序关键字
        /// </summary>
        public string OrderField
        {
            get
            {
                string temp = Request.Form["orderField"];
                return temp;
            }
            set { orderField = value; }
        }
        #endregion

        //
        public string FName = "";
        public string sPId = "";//合作社ID
        //public string sImagePathBase = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            //sImagePathBase = System.Configuration.ConfigurationManager.AppSettings["URLHeader"].ToString() + "UpLoadFile/";
            //传入ID 和操作
            sPId = CommonFunction.getRequestValue("id");
            bindData();
        }

        /// <summary>
        /// 数据绑定，同时需要设置数据总条数
        /// 当前页与每页条数由页面中的pagerForm回传得到
        /// </summary>
        private void bindData()
        {
            string sFilter = buildFilter();
            BLL.ArtelMember bll = new BLL.ArtelMember();
            List<Model.ArtelMember> models = bll.GetModelList(sFilter);
            TotalCount = models.Count;
            RepeaterTr.DataSource = models.Skip((PageNum - 1) * NumPerPage).Take(NumPerPage);
            RepeaterTr.DataBind();
        }

        //生成过滤脚本
        private string buildFilter()
        {
            string sFilter = " 1=1 and sArtelId = '" + sPId + "'";
            //
            FName = Request.Form["FName"];
            if (FName != "")
                sFilter += " And sName Like '%" + FName + "%' ";
            return sFilter;
        }
    }
}